package com.common.File;

import java.io.IOException;

import org.springframework.web.multipart.MultipartFile;

import Decoder.BASE64Decoder;

public class Base64Util {
	 public static MultipartFile base64ToMultipart(String base64) {
        try {
            String[] baseStr = base64.split(",");
 
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] b = new byte[0];
            b = decoder.decodeBuffer(baseStr[1]);
 
            for(int i = 0; i < b.length; ++i) {
                if (b[i] < 0) {
                    b[i] += 256;
                }
            }
 
            return new BASE64DecodedMultipartFile(b, baseStr[0]);
        } catch (IOException e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
}
